import { ApiRootUrl, ImgDomainUrl } from './config/config.js';

var windowInfo = wx.getWindowInfo();
var menuButton = wx.getMenuButtonBoundingClientRect();

App({
  onLaunch: function () {
    this.globalData.navHeight = this.getStatusBarHeight()+this.getTitleBarHeight();//导航栏高度(单位px)
  },

  onShow() { 
    //检查是否最新版本
    this.checkForUpdate();
  },

  checkForUpdate: function () {
    const updateManager = wx.getUpdateManager();
    updateManager.onUpdateReady(function () {
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        success: function (res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })
    updateManager.onUpdateFailed(function () {
      // 新版本下载失败
      wx.showModal({
        title: '已经有新版本了哟~',
        content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
      })
    })
  },

  /**
   * 获取系统状态栏的高度(单位px)
   */
  getStatusBarHeight: function () {
    return windowInfo.statusBarHeight
  },

  /**
   * 获取标题栏的高度(单位px)
   */
  getTitleBarHeight: function () {
    let statusBarHeight = windowInfo.statusBarHeight;
    let capsuleButtonInfo = wx.getMenuButtonBoundingClientRect();
    let gap = capsuleButtonInfo.top - statusBarHeight;
    return gap * 2 + capsuleButtonInfo.height + 4
  },


  globalData: {
    Domain: ApiRootUrl,
    ImgDomain: ImgDomainUrl,
    token: '',
    navHeight: 0
  }
})